home *** CD-ROM | disk | FTP | other *** search
- (*******************************************************************
-
- pack.pas
- --------
-
- (c) 1987, 1988 Attic Software
-
- Pascal routines for PACK segment of Transfer
-
- *******************************************************************)
-
- unit pack;
-
- (******************************************************************)
-
- interface
-
- (******************************************************************)
-
- uses macintf, hfs, types;
-
- (******************************************************************)
-
- implementation
-
- (******************************************************************)
-
- procedure setglobal(value : long); external;
- function getglobal : long; external;
- procedure runiaz(iazaddr : long); external;
-
- (*******************************************************************
-
- function systemdir
- ------------------
-
- This routine is more or less straight out of Tech Note 67. It
- returns a directory id for the System folder, suitable for use
- in “SetVol” calls.
-
- Step one is to find the volume reference number of the volume
- that holds the System folder. “sysmap” is the file reference
- number of the System file (an open file), so “GetVRefNum” will
- find the volume refence number of the System file and, of course,
- the System folder. (The Tech Note skips this step; it searches
- the boot drive for a System folder, and may not find one.)
-
- Step two is to get the directory id, with a call to “PBHGetVInfo”.
- The directory id is returned in the “ioVFndrInfo[1]” field of the
- HParamBlockRec.
-
- *******************************************************************)
-
- function systemdir(globals : wpointer) : long;
-
- var
- thepointer : shortpointer;
- thevolume : integer;
- anerror : integer;
-
- begin
-
- with globals^ do begin
-
- thepointer := shortpointer(sysmap);
- anerror := GetVRefNum(thepointer^, thevolume);
-
- with hblock do begin
- ioNamePtr := nil;
- ioVRefNum := thevolume;
- ioVolIndex := 0;
- end;
- anerror := PBHGetVInfo(@hblock, false);
-
- systemdir := hblock.ioVFndrInfo[1];
-
- end;
-
- end;
-
- (*******************************************************************
-
- function setdir
- ---------------
-
- This is just a shell around “PBHSetVol”.
-
- *******************************************************************)
-
- function setdir(dirid : long; globals : wpointer) : OSErr;
-
- begin
-
- with globals^ do begin
-
- with wdblock do begin
- ioCompletion := nil;
- ioNamePtr := nil;
- ioVRefNum := 0;
- ioWDDirID := dirid;
- end;
-
- setdir := PBHSetVol(@wdblock, false);
-
- end;
-
- end;
-
- (*******************************************************************
-
- procedure postlaunch
- --------------------
-
- This is the routine that performs the actual launch. It is called
- by “InitApplZone” throught the “iaznotify” hook.
-
- First, recover the global record with a call to “getglobal”. This
- routine is called after all the resources have been released; the
- DRVR segment is no longer around, and even if it was, “postlaunch”
- isn't called by it, so we can't find the globals in the usual way.
- “getglobal” will return a long word stored right in the PACK
- segment, which has been previously set to a pointer to the
- globals.
-
- Next, “postlaunch” will call any routines that were already
- installed in “iaznotify” when “postlaunch” was installed there,
- via the “runiaz” routine.
-
- Then it calls “setdir” to set the volume to the folder containing
- the chosen application, and copies the applications's name to
- “curappname”. The system will now be fooled into launching that
- application instead of the FInder.
-
- *******************************************************************)
-
- procedure postlaunch;
-
- var
- globals : wpointer;
- anerror : integer;
-
- begin
-
- globals := wpointer(getglobal);
- with globals^ do begin
- runiaz(iazaddr);
- anerror := setdir(launchpath, globals);
- if anerror = noErr then
- BlockMove(@thename, Ptr(curappname), 32);
- end;
-
- end;
-
- (*******************************************************************
-
- procedure initglobals
- ---------------------
-
- Initialize global data. Note that we preserve the value at
- “iaznotify”; if the current application has installed a routine
- there, we will want to run it before we run ours.
-
- Also, we don't want to confuse the new application with the old
- applications's data files, so we clear the finder files.
-
- *******************************************************************)
-
- procedure initglobals(globals : wpointer);
-
- var
- thepointer : longpointer;
- message : integer;
- count : integer;
- index : integer;
-
- begin
-
- setglobal(long(globals));
-
- with globals^ do begin
-
- sysdir := systemdir(globals);
-
- thepointer := longpointer(iaznotify);
- iazaddr := thepointer^;
-
- launchaddr := BitAnd(long(@postlaunch), $FFFFFF);
-
- end;
-
- CountAppFiles(message, count);
- for index := 1 to count do
- ClrAppFiles(index);
-
- end;
-
- (******************************************************************)
-
- end.
-
- (******************************************************************)
-